/**
 * 
 */
package com.neal.domain.securities;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 
 * @author Neal
 * @version 1.0
 * @description 角色
 */
@Entity
@Table(name="SYS_ROLE")
public class Role {
	/**
	 * 主键
	 */
	@Id	@Column(name="ROLE_ID",length=36)
	private String id;

	/**
	 * 名称
	 */
	@Column(name="ROLE_NAME")
	private String name;

	/**
	 * 状态
	 */
	@Column(name="ROLE_STATUS")
	private boolean status;
	
	@Transient
	private List<Boolean> boolList = new ArrayList<Boolean>();
	
	@Transient
	private boolean[] bs = new boolean[] {};
	
	/**
	 * 角色权限
	 */
	/*@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name="SYS_ROLE_FUNC",
			joinColumns = @JoinColumn(name="ROLE_ID"),
			inverseJoinColumns = @JoinColumn(name="FUNC_ID")
			)
	private List<Function> functions = new ArrayList<Function>();*/

	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name="SYS_ROLE_RESOURCE",
			joinColumns = @JoinColumn(name="ROLE_ID"),
			inverseJoinColumns = @JoinColumn(name="RES_ID")
			)
	private List<Resources> resources = new ArrayList<Resources>();
	
	/**
	 * 构造初始化UUID
	 */
	public Role() {
		this.id = UUID.randomUUID().toString();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	
	public List<Boolean> getBoolList() {
		return boolList;
	}

	
	public void setBoolList(List<Boolean> boolList) {
		this.boolList = boolList;
	}

	
	public boolean[] getBs() {
		return bs;
	}

	
	public void setBs(boolean[] bs) {
		this.bs = bs;
	}


	
	public List<Resources> getResources() {
		return resources;
	}

	
	public void setResources(List<Resources> resources) {
		this.resources = resources;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Role other = (Role) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
